﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

using EPiServer.Research.MobileCenter.JSON;
using EPiServer.Research.MobileCenter.Core;

namespace iPhoneTesting
{
    public class TryOutWebService
    {
 

        public void TestAvailableGadgets()
        {
           
        }

        public JSONGadgetHolder GetAllGadgets()
        {
            JSONGadgetHolder holder = MobileCenterFactory.Instance.GetAllJsonForMobileCenter();

            if (holder.gadgets.Count == 0)
            {
                throw new Exception("no gadgets are available for this user, go into the dashboard for this user and add gadgets (remember to click save)");
            }

            return holder;
        }

        public void CheckGadgetsChildren()
        {
            var holder = GetAllGadgets();
            foreach (var item in holder.gadgets)
            {
                if (String.IsNullOrEmpty(item.name))
                {
                    throw new Exception("gadget missing name");
                }
                foreach (var child in item.gadgets)
                {
                    if (child == null)
                    {
                        throw new Exception(String.Format("Error whith child of gadget {0}", item.name));
                    }
                }
            }
        }

    }
}
